<template>
    <el-dialog title="互评结果" v-model="openPeopleResult" width="33%" class="" append-to-body>
      <div class="dialog-top-line"></div>
      <el-form ref="peopleResultRef" :model="formPeopleResult" :rules="peopleResultRules" label-width="96px">
        <el-row style="margin: 19px 0px;">
          <el-col :span="24">
            <el-form-item label="民主评议对象">
              <el-input v-model="formPeopleResult.reviewUserName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="评定结果" prop="grade">
              <el-select v-model="formPeopleResult.grade" placeholder="请选择评定结果" clearable>
                <el-option
                  v-for="dict in pb_evaluate_result"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="dialog-bottom-line"></div>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitPeopleResult">确 定</el-button>
          <el-button @click="cancelPeopleResult">取 消</el-button>
        </div>
      </template>
    </el-dialog>
</template>

<script setup>
import { comment } from "@/api/partybuilding/Review";
const { proxy } = getCurrentInstance();
const emit = defineEmits(['callBack']);
const openPeopleResult = ref(false);
const { pb_evaluate_result } = proxy.useDict("pb_evaluate_result");

const data = reactive({
    formPeopleResult: {
        reviewId: null,
        reviewedUser: null,
        reviewUserName: null,
        grade: null
    },
    peopleResultRules: {
        grade: [
            { required: true, message: "评定结果不能为空", trigger: "blur" }
        ]
    },
});

const { formPeopleResult, peopleResultRules } = toRefs(data);

const showPeopleResult = (row) => {
  formPeopleResult.value.reviewId = row.reviewId;
  formPeopleResult.value.reviewedUser = row.reviewedUser;
  formPeopleResult.value.reviewUserName = row.reviewedUserName;
  formPeopleResult.value.grade = row.grade;
  openPeopleResult.value = true;
};

defineExpose({
    showPeopleResult
});

// 提交互评结果
function submitPeopleResult() {
  proxy.$refs["peopleResultRef"].validate(valid => {
    if (valid) {
      comment(formPeopleResult.value).then(response => {
        proxy.$modal.msgSuccess("评定成功");  
        openPeopleResult.value = false;
        emit('callBack', {});
      });
    }
  });
}

// 取消互评结果弹窗
function cancelPeopleResult() {
  openPeopleResult.value = false;
  emit('callBack', {});
}
</script>
<style lang="scss" scoped>
.spanUserTitle {
  height: 22px;
  background-color: rgb(255, 255, 255);
  color: rgb(51, 51, 51);
  font-size: 16px;
  text-align: left;
  font-family: PingFangSC-Regular;
}
.itemTogetherTitle {
    font-size: 14px;
    text-align: left;
    font-family: PingFangSC-Regular;
    color: rgb(153, 153, 153) !important;
    padding: 19px 59px;
}
.dialog-top-line {
  width: 100%;
  height: 1px;
  background-color: #ccc;
  position: absolute;
  left: 0px;
  top: 49px;
}
.dialog-bottom-line {
  width: 100%;
  height: 1px;
  background-color: #ccc;
  position: absolute;
  left: 0px;
  bottom: 65px;
}
</style>